package com.wd.tech.view.activity;

import android.content.SharedPreferences;
import android.util.Log;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wd.tech.R;
import com.wd.tech.adapter.News.NewsDetailsAdapter;
import com.wd.tech.base.BaseActivity;
import com.wd.tech.base.BasePresenter;
import com.wd.tech.bean.News_Details_Bean;
import com.wd.tech.mvp.IPresenterImpl;
import com.wd.tech.url.BaseUrl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class News_DetailsActivity extends BaseActivity {



    private NewsDetailsAdapter newsDetailsAdapter;
    private RecyclerView detailsrecy;
    private List<News_Details_Bean.ResultBean> list = new ArrayList<>();


    @Override
    protected void initData() {
        SharedPreferences newsid = getSharedPreferences("Newsid", MODE_PRIVATE);
        int news_id = newsid.getInt("News_id", 0);
        Log.e("资讯详情页id",news_id+"");
        Map<String ,Object> map = new HashMap<>();
        map.put("id",news_id);
        mPresenter.PresenterGetNewsShow(BaseUrl.Details,map,News_Details_Bean.class);
        detailsrecy.setLayoutManager(new LinearLayoutManager(News_DetailsActivity.this));
    }

    @Override
    protected void initView() {
        detailsrecy = findViewById(R.id.details_recycle);
    }

    @Override
    protected BasePresenter initPresenter() {
        return new IPresenterImpl();
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_news_details;
    }


    @Override
    public void success(Object o) {

        if (o instanceof News_Details_Bean){
            list.clear();
            list.add(((News_Details_Bean) o).getResult());
            newsDetailsAdapter = new NewsDetailsAdapter(News_DetailsActivity.this,list);
            detailsrecy.setAdapter(newsDetailsAdapter);
        }

    }

    @Override
    public void Error(Throwable throwable) {

    }
}
